package com.wing.user.service;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.wing.user.dao.ClientDao;
import com.wing.user.model.entity.Client;
import com.wing.user.model.request.ClientForm;
import com.wing.user.model.response.ClientVO;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

/**
 * 客户端-ServiceImpl
 *
 * @author
 */
@Service
@Slf4j
public class ClientServiceImpl extends ServiceImpl<ClientDao, Client> implements ClientService {

    @Override
    public int add(ClientForm clientForm) {

        //校验
        Client client =new Client(
                clientForm.getClientId(),
                clientForm.getClientSecret(),
                clientForm.getScopes(),
                clientForm.getResourceIds(),
                clientForm.getGrantTypes(),
                clientForm.getRedirectUris(),
                clientForm.getAutoApproveScopes(),
                clientForm.getAccessTokenValiditySeconds(),
                clientForm.getRefreshTokenValiditySeconds(),
                clientForm.getAuthorityIds()
        );
        return baseMapper.insert(client);
    }

    @Override
    public List<ClientVO> list4app(Map<String, Object> params) {
        return baseMapper.list4app(params);
    }

    @Override
    public Page<ClientVO> pageList4app(Page page, Map<String, Object> params) {
        List<ClientVO> list = baseMapper.list4app(page, params);
        page.setRecords(list);
        return page;
    }

    @Override
    public ClientVO get4appById(Long id) {
        return baseMapper.get4appById(id);
    }

    @Override
    public ClientVO getByClientId(String clientId) {
        return baseMapper.getByClientId(clientId);
    }
}
